package com.galaxy.user.controller;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.user.domain.UserAccount;
import com.galaxy.user.domain.bo.UserAccountBo;
import com.galaxy.user.domain.vo.UserAccountVo;
import com.galaxy.user.service.UserAccountService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
@RequestMapping("/account")
public class UserAccountController {

    private final UserAccountService userAccountService;

    @SaCheckPermission("user:account:list")
    @GetMapping("/list")
    public TableDataInfo<UserAccountVo> list(UserAccountBo bo, PageQuery pageQuery) {
        return userAccountService.queryPageList(bo, pageQuery);
    }

    @SaCheckPermission("user:account:query")
    @GetMapping("/{id}")
    public R<UserAccount> getInfo(@PathVariable Long id) {
        return R.ok(userAccountService.queryById(id));
    }

    @SaCheckPermission("user:account:add")
    @PostMapping
    public R<Boolean> add(@RequestBody UserAccountBo bo) {
        return R.ok(userAccountService.insertByBo(bo));
    }

    @SaCheckPermission("user:account:edit")
    @PutMapping
    public R<Boolean> edit(@RequestBody UserAccountBo bo) {
        return R.ok(userAccountService.updateByBo(bo));
    }

    @SaCheckPermission("user:account:remove")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable List<Long> ids) {
        return R.ok(userAccountService.deleteWithValidByIds(ids, true));
    }
}
